<?php

/**
 * 
 * 
 */
function _frontend_preset_custom_activities_recommended($view){
	$cityTerm = cache_get('current_city_term');
    
    if (empty($cityTerm->data)) {
        return null;
    }
    $cityTermId = $cityTerm->data->tid;
    
    $nodeIds = _frontend_preset_activities_recommended_pager($view);

    $activities = node_load_multiple($nodeIds);
    $re = node_view_multiple($activities, 'logo');
    
    
    $re['pager'] = array(
      '#theme' => 'glools_pager',
      '#weight' => 5,
      '#quantity' => 3,
      '#element' => 'activities/recommended/pager'
    );
    
    return $re;
}

function _frontend_preset_activities_recommended_pager($view){
    $cityTerm = cache_get('current_city_term');
    
    if (empty($cityTerm->data)) {
        return null;
    }
    $cityTermId = $cityTerm->data->tid;
    Glools_Inc_Tools::loadInc('pager', 'libraries', 'frontend');
    $query = db_select('node', 'n')->extend('GloolsPagerDefault');
    $query->join('field_data_field_city', 'c', "c.entity_id =n.nid");
    $query->fields('n', array('nid'));
    $query->condition('n.type', 'activity')
          //->condition('n.sticky', 1)
          ->condition('c.field_city_tid', $cityTermId);
    $query->limit(1);
    $query->addMetaData('page-owner', 'activities/recommended/pager');
    
    $fetched = $query->execute()->fetchAllAssoc('nid');
    
    return array_keys($fetched);
}